<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item', item.id==0?'mui-active':'']"
            v-for="(item,index) in mav"
            :key="index"
            @click="getPhotos(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul>
      <router-link v-for="(item,index) in newPhotos" :key="index" tag="li" :to="'/Home/photosInfo/'+item.id">
        <img :src="item.img_url">
        <div class="info">
          <h3> {{ item.title }} </h3>
          <p> {{ item.zhaiyao }} </p>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
//导入mui的js文件
import mui from "../../assets/lib/js/mui.min.js";
export default {
  data() {
    return {
      mav: [],
      newPhotos:[]
    };
  },
  created() {
    this.getAllCategory();
    this.getPhotos(0)
  },
  mounted() {
    //初始化滑动控件
    mui(".mui-scroll-wrapper").scroll({
      //当组件中的DOM结构被渲染好并放在页面中后,会执行这个钩子函数
      //如果要操作元素了这个时候 是最好的
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getAllCategory() {
      this.axios.get("api/getimgcategory").then(res => {
        console.log(res.data.message);
        res.data.message.unshift({
          title: "全部",
          id: 0
        });
        this.mav = res.data.message;
      });
    },
    getPhotos(ID){
      this.axios.get("api/getimages/"+ID).then(res=>{
        console.log(res.data.message);
        this.newPhotos=res.data.message
      })
    }
  }
};
</script>
<style lang="less" scoped>
* {
  touch-action: pan-y;
}
ul{
  list-style: none;
  padding: 10px;
  padding-bottom: 0;
  li{
    margin-bottom: 10px;
    background-color: #ccc;
    position: relative;
    img{
      width: 100%;
      vertical-align: middle;
    }
    .info{
      color: #fff;
      text-align: left;
      position: absolute;
      bottom: 0;
      background-color: rgba(11, 33, 4, .3);
      h3{
        font-size: 17px;
      }
      p{
        font-size: 13px;
        color: #fff;
      }
    }
  }
}
</style>